using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Enum;
using Common.NotifyEvent;

namespace SProject.BasicInformation
{
	[Serializable]
	public class BasicInfo : NotifyPropertyChanged
	{
		public const int MinReaction = 15;

		public const int MaxReaction = 100;

		private EProjectType _Type;

		private string _Name = "";

		private double _Reaction = 30.0;

		private string _Unit = Utility.GetMessage("default_unit");

		private List<string> _TestType = new List<string>();

		private string _Note = "";

		private string _Version = "";

		private bool _TubeSortByColumn = true;

		private bool _IsReadOnly;

		public EProjectType Type
		{
			get
			{
				return _Type;
			}
			set
			{
				if (_Type != value)
				{
					EProjectType type = _Type;
					_Type = value;
					OnPropertyChanged("Type", _Type, type);
				}
			}
		}

		public string Name
		{
			get
			{
				return _Name;
			}
			set
			{
				if (!(_Name == value))
				{
					string name = _Name;
					_Name = value;
					OnPropertyChanged("Name", _Name, name);
				}
			}
		}

		public double Reaction
		{
			get
			{
				return _Reaction;
			}
			set
			{
				if (_Reaction != value)
				{
					_Reaction = value;
					OnPropertyChanged("Reaction");
				}
			}
		}

		public string Unit
		{
			get
			{
				return _Unit;
			}
			set
			{
				if (!(_Unit == value))
				{
					_Unit = value;
					OnPropertyChanged("Unit");
				}
			}
		}

		public List<string> TestType
		{
			get
			{
				return _TestType;
			}
			set
			{
				if (_TestType != value)
				{
					_TestType = value;
					OnPropertyChanged("TestType");
				}
			}
		}

		public string Note
		{
			get
			{
				return _Note;
			}
			set
			{
				if (!(_Note == value))
				{
					_Note = value;
					OnPropertyChanged("Note");
				}
			}
		}

		public string Version
		{
			get
			{
				return _Version;
			}
			set
			{
				if (!(_Version == value))
				{
					_Version = value;
					OnPropertyChanged("Version");
				}
			}
		}

		public bool TubeSortByColumn
		{
			get
			{
				return _TubeSortByColumn;
			}
			set
			{
				if (_TubeSortByColumn != value)
				{
					_TubeSortByColumn = value;
					OnPropertyChanged("TubeSortByColumn");
				}
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return _IsReadOnly;
			}
			set
			{
				if (_IsReadOnly != value)
				{
					_IsReadOnly = value;
					OnPropertyChanged("IsReadOnly");
				}
			}
		}

		public BasicInfo()
		{
			_Name = ProjectManage.GetInstance().GetNewProjectName();
		}

		public BasicInfo(BasicInfo basic)
		{
			Copy(basic);
		}

		public void Copy(BasicInfo basic)
		{
			Type = basic.Type;
			Name = basic.Name;
			Reaction = basic.Reaction;
			Unit = basic.Unit;
			Note = basic.Note;
			TubeSortByColumn = basic.TubeSortByColumn;
			IsReadOnly = basic._IsReadOnly;
			TestType.Clear();
			foreach (string item in basic.TestType)
			{
				TestType.Add(item);
			}
		}

		public void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_ProjectBasicInfo);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			list.Add(PropertyKey.Key_Type);
			list2.Add(BytesConverter.GetBytes((int)Type));
			if (!string.IsNullOrEmpty(Name))
			{
				list.Add(PropertyKey.Key_Name);
				list2.Add(BytesConverter.GetBytes(Name));
			}
			list.Add(PropertyKey.Key_Reaction);
			list2.Add(BytesConverter.GetBytes(Reaction));
			if (!string.IsNullOrEmpty(Unit))
			{
				list.Add(PropertyKey.Key_Unit);
				list2.Add(BytesConverter.GetBytes(Unit));
			}
			if (!string.IsNullOrEmpty(Note))
			{
				list.Add(PropertyKey.Key_Note);
				list2.Add(BytesConverter.GetBytes(Note));
			}
			if (!string.IsNullOrEmpty(Version))
			{
				list.Add(PropertyKey.Key_Version);
				list2.Add(BytesConverter.GetBytes(Version));
			}
			list.Add(PropertyKey.Key_TubeSortByColumn);
			list2.Add(BytesConverter.GetBytes(TubeSortByColumn));
			list.Add(PropertyKey.Key_IsReadOnly);
			list2.Add(BytesConverter.GetBytes(IsReadOnly));
			list.Add(PropertyKey.Key_TestType);
			StreamEx streamEx = new StreamEx();
			streamEx.Write(BytesConverter.GetBytes(_TestType.Count));
			foreach (string item in _TestType)
			{
				streamEx.Write(item);
			}
			streamEx.Seek(0L, SeekOrigin.Begin);
			list2.Add(streamEx.ToArray());
			streamEx.Close();
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_ProjectBasicInfo)
			{
				Unit = string.Empty;
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						StreamEx streamEx = null;
						int num = 0;
						switch (keys[i])
						{
						case PropertyKey.Key_Type:
							Type = (EProjectType)BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_Name:
							Name = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_Reaction:
							Reaction = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_Unit:
							Unit = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_Note:
							Note = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_Version:
							Version = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_TubeSortByColumn:
							TubeSortByColumn = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_IsReadOnly:
							IsReadOnly = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_TestType:
						{
							streamEx = new StreamEx();
							streamEx.Write(dates[i]);
							streamEx.Seek(0L, SeekOrigin.Begin);
							num = streamEx.ReadInt();
							for (int j = 0; j < num; j++)
							{
								string item = streamEx.ReadString();
								TestType.Add(item);
							}
							streamEx.Close();
							break;
						}
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				while (true)
				{
					switch (stream.ReadKey())
					{
					case PropertyKey.Key_Type:
						Type = (EProjectType)stream.ReadInt();
						break;
					case PropertyKey.Key_Name:
						Name = stream.ReadString();
						break;
					case PropertyKey.Key_Reaction:
						Reaction = stream.ReadDouble();
						break;
					case PropertyKey.Key_Unit:
						Unit = stream.ReadString();
						break;
					case PropertyKey.Key_Note:
						Note = stream.ReadString();
						break;
					case PropertyKey.Key_TubeSortByColumn:
						TubeSortByColumn = stream.ReadBool();
						break;
					default:
						stream.Seek(-4L, SeekOrigin.Current);
						return true;
					}
				}
			}
			stream.Seek(-4L, SeekOrigin.Current);
			return false;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			BasicInfo basicInfo = obj as BasicInfo;
			if (basicInfo == null)
			{
				return false;
			}
			if (base.Equals(basicInfo))
			{
				return true;
			}
			if (Type == basicInfo.Type && Name == basicInfo.Name && Version == basicInfo.Version && Reaction == basicInfo.Reaction && Unit == basicInfo.Unit && Note == basicInfo.Note && TubeSortByColumn == basicInfo.TubeSortByColumn)
			{
				return IsReadOnly == basicInfo.IsReadOnly;
			}
			return false;
		}
	}
}
